<template>
    <view class="page-container page-container__footer">
        <swiper class="swiper" indicator-dots indicator-active-color="pink" autoplay>
            <swiper-item v-for="(item, index) in bannerList" :key="index">
                <image class="swiper-item" :src="item" mode="widthFix"> </image>
            </swiper-item>
        </swiper>
        <!-- <view class="grid">
            <view class="grid-item" @click="showTips">
                <view class="grid-top">
                    <text class="hx-icon-rili grid-icon"></text>
                </view>
                <view class="grid-name">婚礼档期</view>
            </view>
        </view> -->
        <view class="list">
            <view :class="`list-item bg${item.type.id}`" v-for="(item, index) in list" :key="index">
                <view class="list-head">
                    <view class="list-type">{{ item.type.name }} </view>
                    <view class="list-head__right">
                        <view class="list-time__name" :class="{ 'night-time': item.day_time === 1 }">
                            {{ dayEnums[item.day_time] }}
                        </view>
                        <view class="line ml2 mr2">|</view>
                        <view class="list-status" :class="{ status1: $countAcitivityStatus(item.using_date) === '进行中', status2: $countAcitivityStatus(item.using_date) === '已结束' }">
                            {{ $countAcitivityStatus(item.using_date) }}
                        </view>
                    </view>
                </view>
                <view class="list-body">
                    <view class="list-left">
                        <view class="list-name">{{ item.subject }}</view>
                        <view class="list-date">{{ item.using_date }}</view>
                    </view>
                    <button class="btn-danger btn-square btn-small" v-if="item.status === 1" @click="$navPage(`./control/index?aid=${item.aid}`)">遥控本场</button>
                </view>
                <view class="list-footer">
                    <button class="btn-text" @click="$navPage(`./set?id=${item.id}&index=0`)">设置</button>
                    <!-- <button class="btn-text" @click="$navPage('./evaluation')">查看评论</button> -->
                    <!-- <button class="btn-text" @click="$navPage(`./set?id=${item.id}&index=1`)">查看收益</button> -->
                </view>
            </view>
        </view>
        <view class="page-footer">
            <button class="btn-red btn-square flex" @click="$navPage('./add')">添加活动</button>
        </view>
        <load-more :loadingType="loadingType" />
    </view>
</template>
<script>
import { nameEnums, dayEnums } from "@/utils/global"
export default {
    data() {
        return {
            dayEnums,
            bannerList: [
                "https://haixihudong.oss-cn-hangzhou.aliyuncs.com/static/banner/100.jpg",
                "https://haixihudong.oss-cn-hangzhou.aliyuncs.com/static/banner/101.jpg",
                "https://haixihudong.oss-cn-hangzhou.aliyuncs.com/static/banner/102.jpg"
            ],
            nameEnums,
            list: [],
            params: {
                page: 1,
                limit: 10
            },
            loadingType: ""
        }
    },
    onShow() {
        this.loadData()
    },
    methods: {
        showTips() {
            return this.$showToast("功能正在开发中")
        },
        async loadData(type = "refresh") {
            try {
                if (type === "refresh") {
                    this.$showLoading("加载中")
                    this.params.page = 1
                } else if (this.loadingType === "nomore" || this.loadingType === "nodata") return
                this.loadingType = "loading"
                let { list, count: total } = await this.$api.activityList(this.params)
                await this.$setTime(300)
                let loadingType = ""
                if (type === "refresh") {
                    this.list = list
                    uni.pageScrollTo({ scrollTop: 0, duration: 0 })
                    if (list.length === 0) loadingType = "nodata"
                    uni.hideLoading()
                } else {
                    this.list = this.list.concat(list)
                }
                if (this.list.length === total && total !== 0) {
                    loadingType = "nomore"
                }
                if (!loadingType) this.params.page++
                this.loadingType = loadingType
            } catch {
                this.loadingType = ""
            }
        }
    },
    onPullDownRefresh() {
        this.loadData()
        uni.stopPullDownRefresh()
    },
    onReachBottom() {
        this.loadData("more")
    }
}
</script>
<style lang="scss" scoped>
.swiper {
    width: 100%;
    height: 400rpx;
    &-item {
        width: 100%;
    }
}
.list {
    &-item {
        margin: 30rpx;
        border: $border-1;
        border-radius: 20rpx;
        background: #fff;
    }
    &-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 100rpx;
        padding: 0 20rpx;
        &__right {
            display: flex;
        }
    }
    &-type {
        color: #fff;
        min-width: 160rpx;
        height: 62rpx;
        line-height: 62rpx;
        padding: 0 10rpx;
        text-align: center;
        border-radius: 10rpx;
        font-size: 32rpx;
        box-sizing: border-box;
    }
    .bg1 .list-type {
        background: #ff1184;
    }
    .bg2 .list-type {
        background: $light-blue;
    }
    .bg3 .list-type {
        background: #f9eded;
        color: #333;
    }
    .bg4 .list-type {
        background: red;
    }
    .bg5 .list-type {
        background: #f24848;
    }
    .bg6 .list-type {
        background: $light-green;
    }
    .bg10 .list-type {
        background: red;
    }
    .bg11 .list-type {
        background: $light-green;
    }

    &-time__name {
        width: 90rpx;
        height: 40rpx;
        font-size: 26rpx;
        background: rgba(#e6b241, 0.1);
        border-radius: 6rpx;
        text-align: center;
        line-height: 40rpx;
        color: #e6b241;
        &.night-time {
            color: #333;
            background: rgba(#333, 0.1);
        }
    }
    .line {
        color: #ccc;
    }
    &-status {
        font-size: 26rpx;
        color: #999;
        &.status1 {
            color: $blue-1;
        }
        &.status2 {
            color: $green;
        }
    }
    &-body {
        display: flex;
        align-items: center;
        position: relative;
        padding: 10rpx 30rpx 20rpx 30rpx;
        &::after {
            @include _border;
        }
    }
    &-left {
        flex: 1;
    }
    &-name {
        font-size: 32rpx;
        margin-bottom: 10rpx;
    }
    &-date {
        font-size: 26rpx;
        color: #999;
    }
    &-footer {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        height: 80rpx;
        padding: 0 20rpx;
    }
}
.grid {
    display: flex;
    flex-wrap: wrap;
    padding: 0 20rpx;
    margin-top: 30rpx;
    &-item {
        flex: 0 0 calc(25% - 20rpx);
        padding: 10rpx 20rpx;
        margin: 10rpx;
        box-sizing: border-box;
        border: 1px solid $light-blue;
        border-radius: 10rpx;
    }
    &-top {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 80rpx;
    }
    &-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 40rpx;
        color: $light-blue;
        width: 80rpx;
        height: 80rpx;
        border-radius: 50%;
        background: rgba($light-blue, 0.3);
    }
    &-name {
        margin-top: 10rpx;
        font-size: 28rpx;
        color: #333;
    }
}
.menu-icon {
    position: fixed;
    text-align: center;
    line-height: 60rpx;
    width: 60rpx;
    height: 60rpx;
    border-radius: 50%;
    background: rgba($color: #000, $alpha: 0.2);
    z-index: 9;
    top: 30rpx;
    right: 30rpx;
    color: #fff;
    font-size: 32rpx;
}
</style>
